
#include "Player.h"

Player::Player() : Character()
{
    health = 600;
    DEFAULT_P_HEALTH = health;
    damage = 35;
    animation_speed=0;

    //all stuff for Character animation
    character_image.load("grafx/character/characterwalk.png");
    heart.load("grafx/health.png");
    moving_right = true;
    frame=0;

    sprite_info.w = 45;
    sprite_info.h = 90;

    player_sinking = false;
}

Player::~Player()
{

}

void Player::Draw( int x, int y)
{
    sprite_info.x = x;

    if( true == player_sinking )
    {
        sprite_info.y += 6;
    }
    else
    {
        sprite_info.y = y;
    }

    if(moving_right)
    {
        if (jumped)
            character_image.drawAnim(x, sprite_info.y, sprite_info.w, sprite_info.h, 90, 0);
        else
            character_image.drawAnim(x, sprite_info.y, sprite_info.w, sprite_info.h, frame, 0);
    }
    else
    {
        if(jumped)
            character_image.drawAnim(x, sprite_info.y, sprite_info.w, sprite_info.h, 90, 100);
        else
            character_image.drawAnim(x, sprite_info.y, sprite_info.w, sprite_info.h, frame, 100);
    }
    DrawHealth();

   // Player_sinking();
}

void Player::Move_frame()
{
    if(animation_speed == 3)
    {
        if (frame < 360)
        {
            frame=frame+45;
        }
        else
            frame=0;

        animation_speed = 0;
    }
    else
        animation_speed++;

}

void Player::DrawHealth()
{
    int total_hearts =6;

    int red = health/100;
    int half_red = health%100;

    int count = 0;
//Laydown black hearts
    for(int i=1; i<=6; i++)
    {
        heart.drawAnim(25+count, 25, 30, 30, 30, 0);
        count+=30;
    }
    count=0;
//Draw red hearts over the black
    for(int i=1; i<=red; i++)
    {
        heart.drawAnim(25+count, 25, 30, 30, 0, 0);
        count+=30;
    }
    total_hearts -=red;
//Draw half hearts

    if(half_red >= 50)
        heart.drawAnim(25+count, 25, 30, 30, 60, 0);
    if(health>0 && health<50)
        heart.drawAnim(25+count, 25, 30, 30, 60, 0);

}

void Player::Set_player_sinking( bool sinking )
{
    player_sinking = sinking;
}

